#define ASM_SOURCE
#include "uart.h"
#define COUNTER_FREQUENCY       (0x1800000) /* 24MHz */

.global board_init
.global _entry_start
.global __real_exit

_entry_start:
    /*************************************/
    msr SCR_EL3, xzr  // Ensure NS bit is initially clear, so secure copy of ICC_SRE_EL1 can be configured
    isb

    // neither EL3 nor EL2 trap floating point or accesses to CPACR
    msr CPTR_EL3, xzr
    msr CPTR_EL2, xzr

    mov x0, #1 << 8
    msr CPTR_EL3, x0            /* sve trap */

    mov x0, #3 << 20
    mov x1, #3 << 16            /* sve Enable */
    orr x0, x0, x1                  
    msr cpacr_el1, x0           /* Enable FP/SIMD */
    msr mdscr_el1, xzr
    /************************************/

	ldr x0, =stack_top
	mov sp, x0
	bl __counter_init
	bl board_init
	bl main
	bl __real_exit
	b .


__counter_init:
    // ldr x0, =COUNTER_FREQUENCY
    // msr cntfrq_el0, x0          /* Initialize CNTFRQ */
    // mrs x0, cntpct_el0
    ret

// __read_counter:
//     mrs x0, cntpct_el0
//     ret

.align 8
__real_exit:
	mov x0, #0x4
	bl uart_putc
	wfe
    wfi
	b __real_exit
	